home *** CD-ROM | disk | FTP | other *** search
- Path: noc.tor.hookup.net!the-fix.sos.on.ca
- From: <verneb@the-fix.sos.on.ca>
- Date: Sat,20 Jan 96 14:37:24 -0500
- Newsgroups: comp.lang.c
- Subject: why is this an infinite loop?
- Message-ID: <tcpnntpd.16.1.20.14.37.24.2781597121.351172@the-fix.sos.on.ca>
- References: <4dp9p5$jm2@news1.wolfe.net>
- Organization: the FIX - Kitchener, Ontario CANADA
- NNTP-Posting-Host: the-fix.sos.on.ca
- X-MajorTCP-Version: MajorTCP/IP [1.81-2]
-
- To: INT:neus@wolfenet.com
-
- Int:neus@wolfenet.com,
-
- I >Beginning c student can't figure out why this small function to read in a
- I >value for the variable x causes an infinite loop when it receives
- I >unexpected
- I >input.
- I >
- I >double get_x()
- I >{
- I >int test;
- I >double x;
- I >
- I >printf("Enter a numeric value for x: ");
- I >
- I >while(scanf("%lf", &x) != 1)/*could be here! change to ==1 */
- I >{
- I >printf("ERROR - program expecting a number");
- I >printf("Enter a numeric value for x: ");
- I >}
- I >
- I >return x;
- I >}
- I >
- I >
-
- Verne H. Bohlender
- Box 416, Chesley, Ontario.Ca. N0G 1L0
- verneb@The-Fix.sos.on.ca
- ___
- * UniQWK #2158*
-
-